/**
 * 
 */
package com.scpii.universal.struts.manage;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.comm.paginaction.Pagination;
import com.scpii.universal.action.BaseAction;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.OrderDto;
import com.scpii.universal.hibernate.entity.OrderTab;
import com.scpii.universal.service.OrderManageService;
import com.scpii.universal.service.OrderService;

/**
 * universalWeb
 * 
 * @author weny 2012-7-9下午05:20:49
 */
@Controller
@Scope("prototype")
public class OrderAction extends BaseAction {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4629317011625914415L;
	@Resource
	private OrderManageService orderManageService;
	@Resource
	private OrderService orderService;

	private Pagination page = new Pagination();

	private List<OrderDto> orderList;

	private OrderDto orderInfo;

	private OrderDto condition;

	public String getOrderPage() {

		// modify by zhangqiang 20120725
		// UserInfoDto userInfoDto=(UserInfoDto)
		// session.getAttribute("userInfoDto");
		if (condition == null) {
			condition = new OrderDto();
		}
		condition.setIntAppId(getUserInfo().getAppId());

		// 获取返回信息的条数
		Integer recordCount = orderManageService.getOrderRecode(condition);

		if (getSelectPerPage("page") == -1) {
			page.setPageRecord(GenericConstants.PAGE_NO);
		} else {
			page.setPageRecord(getSelectPerPage("page"));
		}
		// 判断是否是第一次查询
		if (getQueryFlag("page") == -1) {
			page.setTotalRecord(recordCount);
		} else {
			page.setTotalRecord(getQueryFlag("page"));
		}
		setPageParameters(page, "page");
		// 获取页面返回list
		orderList = orderManageService.getOrderListPage(condition,
				page.getCurrentPage(), page.getPageStart(),
				page.getPageRecord());
		
		//获取订单状态
		

		return SUCCESS;
	}

	/**
	 * 获取分享信息
	 * 
	 * @return
	 * @author weny 2012-7-13上午10:00:26
	 */
	public String getOrder() {
		String intOrderId = request.getParameter("intOrderId");
		orderInfo = orderManageService
				.getOrderInfo(Integer.valueOf(intOrderId));
		return SUCCESS;
	}

	/**
	 * 删除状态更新
	 * 
	 * @return
	 * @author weny 2012-7-17下午05:28:20
	 */
	public String delOrder() {
		String intOrderId = request.getParameter("intOrderId");
		OrderTab orderTab = orderService.get(Integer.valueOf(intOrderId));
		orderTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_DELETED);
		orderService.update(orderTab);
		return null;
	}

	/**
	 * 订单编辑
	 * 
	 * @return
	 * @author weny 2012-7-18上午11:31:48
	 */
	public String editOrder() {
		orderService
				.updateDetail(orderInfo.getIntOrderId(),
						orderInfo.getDobOrderMoney(),
						orderInfo.getIntOrderCount(),
						orderInfo.getDatOrderDatetime(),
						orderInfo.getIntOrderStatues());
		return SUCCESS;
	}

	// ======================get() set()方法
	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public List<OrderDto> getOrderList() {
		return orderList;
	}

	public void setOrderList(List<OrderDto> orderList) {
		this.orderList = orderList;
	}

	public OrderDto getOrderInfo() {
		return orderInfo;
	}

	public void setOrderInfo(OrderDto orderInfo) {
		this.orderInfo = orderInfo;
	}

	public OrderDto getCondition() {
		return condition;
	}

	public void setCondition(OrderDto condition) {
		this.condition = condition;
	}

}
